import {} from "https://cdn.bootcdn.net/ajax/libs/jquery/1.12.4/jquery.js";

const $tel =$('.tel');
const $tel_empty =$('.tel_empty');
const $tel_flag =$('.tel_flag');
const $tel_error =$('#tel_error');
let $flag ;

const $password =$('.password');
const $pass_empty =$('.pass_empty');
const $pass_flag =$('.pass_flag')
const $pass_tip =$('.pass_tip');
const $pass_error=$('.pass_error');
const $pass_safe=$('.pass_safe');
const $pass_safe_ul=$('.pass_safe ul');
let $flag2;

const $password2 =$('.password2');
const $pass2_tip =$('.pass2_tip');
const $pass2_empty=$('.pass2_empty');
const $pass2_flag=$('.pass2_flag');
const $pass2_error=$('.pass2_error');
let $flag3;

const $regform =$('.regform');

$tel.on('input',function(){
    if($tel.val()==''){
        $tel_error.hide();
        $tel_empty.show();
        $tel_flag.hide();
        $flag=false;
    }else{
        $tel_empty.hide();
    }
});
$tel.on('blur',function(){
    let reg =/^1[3|4|5|7|8][0-9]{9}$/;
    if($tel.val()!==''){
        if(reg.test($tel.val())){
            $.ajax({
                type:'post',
                url:'http://10.31.165.32/com.111.www/php/registry_module.php',
                data:{
                   tel:$tel.val()
                }
            }).done(function(data){
               if(data==1){
                   $tel_error.show();
                   $tel_error.html('该手机号已经注册过了！');
               $flag=false;
               }else{
                   $tel_flag.show();
                   $flag=true;
               }
            });
        }else{
            $tel_flag.hide();
            $tel_error.show();
            $tel_error.html('手机号格式不正确!');
            $flag=false;
        }
    }else{
        $tel_empty.show();
        $flag=false;
    }
});

$password.on('focus',function(){
    if($password.val()==''){
        $pass_empty.hide();
        $pass_tip.show();
    }
});
$password.on('blur',function(){
    $pass_error.hide();
    $pass_tip.hide();
});

$password.on('input',function(){
    if($password.val()==''){
        $pass_error.hide();
        $pass_tip.hide();
        $pass_safe.hide();
        $pass_flag.hide();
        $pass_empty.show();
        $flag2=false;
    }else{
        $pass_empty.hide();
       let len =$password.val().length;
       if(len>=6&&len<=20){
        $pass_error.hide();
        let reg1 = /\d+/; 
        let reg2 = /[a-z]+/; 
        let reg3 = /[A-Z]+/;  
        let count =0;
        if (reg1.test($password.val())) {
            count++;
        }
        if (reg2.test($password.val())) {
            count++;
        }
        if (reg3.test($password.val())) {
            count++;
         }
        switch (count) {
            case 1:
            $pass_safe.show();
            $pass_safe_ul.css('background-position','0px 0px');
            $pass_flag.show();
            $flag2=true;
            break;
            case 2:
            $pass_safe.show();
            $pass_safe_ul.css('background-position','0px -15px');
            $pass_flag.show();
            $flag2=true;
            break;
            case 3:
            $pass_safe.show();
            $pass_safe_ul.css
            ('background-position','0px -30px');
            $pass_flag.show();
            $flag2=true;
            break;
                     
        }   
       }else{
            $pass_error.html('密码长度有误!');
            $pass_safe.hide();
            $pass_tip.hide();
            $pass_flag.hide();
            $pass_error.show();
            $flag2=false;
       }  
    }
});
$password2.on('input',function(){
    if($password2.val()==''){
        $pass2_tip.hide();
        $pass2_empty.hide();
    }
})
$password2.on('focus',function(){
    if($password2.val()==''){
        $pass2_empty.hide();
        $pass2_tip.show();
        $flag3=false;
    } 
});
$password2.on('blur',function(){
    $pass2_tip.hide();
if($password2.val()!==''){
    if($password2.val()===$password.val()){
        $pass2_error.hide();
        $pass2_flag.show();
        $flag3=true;
    }else{
        $pass2_empty.hide();
        $pass2_flag.hide();
        $pass2_error.show();
        $flag3=false;
    }
}else{
    $pass2_error.hide();
    $pass2_empty.show()
    $flag3=false;
} 
})

$regform.on('submit',function(){
    if($tel.val()===''){$flag=false}
    if($password.val()===''){$flag2=false}
    if($password2.val()===''){$flag3=false}
    // console.log($tel.val()==='');
    // console.log($password.val()==='');
    // console.log($password2.val()==='');
    
    if(!$flag||!$flag2||!$flag3){
        return false;
   }
});





